declaration of a →function block, FB_name_2 must be an →IEC-identifier. The declaration is possible within an ST-object or an ST-interface of a C-/C++-block – the declaration is done either within the global →namespace or within a declared namespace. FUNCTION_BLOCK and END_FUNCTION_BLOCK are →keywords for the declaration of the function block.
Neuron Power Engineer supports the following function block variants:
-
function block with a function block body only (the body consists of a set of operations) In this case, the function block has no methods implemented.
-
function block with a function block body and →methods A method is similar to a →function; A method can only be defined in the →scope of a →function block type and has implicit access to →static variables of the →function block instance. A method is declared after the section of the declared →variables/→instances and in front of the body of the function block.
-
function block with methods only In this case, the function block has an empty function block body implemented.
The keywords FINAL and ABSTRACT (features of the →object-oriented programming) are optional. See "Declaration of a method" for an example with an abstract or a final function block.
-
Use the keyword FINAL to indicate that the current function block is not to be a base function block and from which you do not want to derive function blocks. See keyword EXTENDS for details on base function block and derived function block.
-
Use the keyword ABSTRACT to indicate that the current function block is intended to be a base function block from which you want to derive function blocks. There are the following restrictions/consequences:
-
An abstract function block cannot be instantiated.
-
An abstract function block must contain at least one abstract method.
-
As a consequence, a non-abstract function block derived from an abstract function block must include all abstract methods of the abstract function block.
The USING namespace directive after the name of the function block is optional as well. See "Namespaces in ST: usage" for details on this directive.
The keyword EXTENDS (a feature of the →object-oriented programming) is optional as well. Specify EXTENDS , if the function block is to be derived from a different function block (this is the base function block) or from a →class (this is the base class). Specify the name of the base function block or the class after EXTENDS . The impacts of the keyword EXTENDS are:
-
The derived function block FB_name_2 inherits all variables and methods from the base function block FB_name_1 or the class class_name_1 . Of course, you are able to declare its own variables and methods in the derived function blocks. Subsequently, the derived function block may use the inherited variables and methods as well as its own variables and methods. Exceptions from this inheritance are the methods that are declared using the keyword PRIVATE or INTERNAL within the base function block or the base class.
-
When a base function block is mentioned in the following description about EXTENDS and the context can be applied to a class, the description also applies to a base class. In case of any doubts regarding the impacts of EXTENDS on/for classes, contact Neuron).
-
You must use unique names for all variables and methods within the derived function block and within the respective base function block.
-
The base function block itself may be a derived function block. So it is possible to inherit variables and methods over several levels from one function block to another function block. A recursion is not allowed – according to the IEC-standard.
-
If the base function block is changed, the derived function blocks inherits these changes over the corresponding levels.
-
Other restrictions:
-
It is only possible to derive a function block from one base function block that must be a different function block. A derived function block must not inherit from several base function blocks at the same time – this multi-inheritance is not supported by the IEC-standard.
-
It is only possible to derive a function block from a base function block, if this base function block contains methods. The methods might even be contained across several levels, if the base function block itself is a derived function block etc.
-
The derived function block does not automatically inherit the body of the base function block. If you want to execute the body of the base function as well when the derived function block is called, insert the statement SUPER(); within the body of the derived function block. See the following example 3. Restrictions for SUPER(); :
-
SUPER(); is only allowed within a derived function block, hence when the keyword EXTENDS has been specified for the function block.
-
SUPER(); is only allowed to be used once in the body of the derived function block. Subsequently, SUPER(); is not allowed within iterations statements.
-
SUPER(); must not be specified in methods to call a method. Instead, use one of the calls of a method.
-
Alternative to SUPER(); : Move the body of the base function block into a declared method of the base function block and call this method in the derived function block. See the following example 4.
|
The keyword IMPLEMENTS (a feature of the →object-oriented programming) is optional as well. Specify IMPLEMENTS , if the function block is to implement one or more →interfaces. Specify the name of the interfaces after IMPLEMENTS (separated by a comma).
Subsequently, observe that the function block must contain all methods of the interfaces. If not, a message will indicate the missing methods. Best practice is to use the quick fix of Neuron Power Engineer to add the unimplemented methods within the function block. The concrete methods that are declared within the function block are matched with the abstract methods that are declared within the interfaces. Matching is done by using the name of the method only. The methods with the same name must be identical concerning the following aspects:
-
If a data type is required, the data type must be specified in the abstract method as well as in the concrete method. The data type must be of the same type. If no data type is required, a data type must be specified neither in the abstract method nor in the concrete method.
-
All variables that are declared within the abstract method must be identical to the variables that are declared within the concrete method.
|